package com.guchenbo.spark.sql

import org.apache.spark.sql.SparkSession

/**
 * @author guchenbo
 * @date 2022/2/17
 */
object SqlDemo {

  def main(args: Array[String]): Unit = {
    val spark = SparkSession.builder().master("local").appName("demo")
      .config("hive.metastore.uris", "thrift://ark150:9083")

      .enableHiveSupport()
      .getOrCreate()

    val slices = 2

    //    //    val spark = SparkUtils.sparkSession("demo")
    //    var userDf = spark.read.json("file:///sql/user.json")
    //    userDf.show()
    //
    //    val path = "/Users/guchenbo/Downloads/model_report_test2.csv"
    //    var csvDf = spark.read.csv(path)
    //    csvDf.show()
    //
    //    spark.sql(s"create table t02172 (id INT, name STRING, age INT) using csv " +
    //      s"OPTIONS (path='/Users/guchenbo/Downloads/model_report_test2.csv')")
    //    spark.sql("select * from t02172").show()
    //
    //    csvDf.createOrReplaceTempView("csv1")
    //    spark.sql("select * from csv1").show()
    //    spark.sql("show tables").show()
    //
    //    userDf.foreach(r => println(r))
    //
    //    spark.sql("show create table src").foreach(r=>println(r))

    val df = spark.sql("SELECT * FROM turing.gcb_model_data02")
    val rows = df.take(10)
    rows.foreach(r => println(r))
  }

}
